package com.zygk.library.util;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * 所有活动管理器
 */
public class ActivityCollector {

  public static List<Activity> activities = new ArrayList<Activity>();

  /**
   * 添加活动
   */
  public static void addActivity(Activity activity) {
    if (!activities.contains(activity)) {
      activities.add(activity);
    }
  }

  /**
   * 移除活动
   */
  public static void removeActivity(Activity activity) {
    activities.remove(activity);
  }

  /**
   * 结束所有活动
   */
  public static void finishAll() {
    for (Activity activity : activities) {
      if (!activity.isFinishing()) {
        activity.finish();
      }
    }

    // 杀死该应用进程
    //android.os.Process.killProcess(android.os.Process.myPid());
  }

  /**
   * 结束所有活动除了登陆页面
   */
  public static void finishAllExceptLogin(Activity loginActivity) {
    for (Activity activity : activities) {
      if (activity == loginActivity) {
      } else {
        if (!activity.isFinishing()) {
          activity.finish();
        }
      }
    }
  }
}
